local skel = fk.CreateSkill {
  name = "efengqi__kongcheng",
}

Fk:loadTranslationTable{
  ["efengqi__kongcheng"] = "空城",
  [":efengqi__kongcheng"] = "你视为装备【八卦阵】，若你没有手牌，你可以令一名角色获得因此判定的判定牌。",
  ["#efengqi__kongcheng-give"] = "空城：你可以令一名角色获得判定牌%arg",

  ["$efengqi__kongcheng1"] = "（悠扬的琴音）",
  ["$efengqi__kongcheng2"] = "（低沉的琴音）",
}

local skel_on_use = function (self, event, target, player, data)
  local room = player.room
  room:broadcastPlaySound("./packages/standard_cards/audio/card/eight_diagram")
  room:setEmotion(player, "./packages/standard_cards/image/anim/eight_diagram")
  local skill = Fk.skills["#eight_diagram_skill"] ---@type TriggerSkill
  skill:use(event, target, player, data)
end

skel:addEffect(fk.AskForCardUse, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and not player:isFakeSkill(self) and
      Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none") and
      not player:prohibitUse(Fk:cloneCard("jink")) and
      not player:getEquipment(Card.SubtypeArmor)
      and Fk.skills["#eight_diagram_skill"] ~= nil and Fk.skills["#eight_diagram_skill"]:isEffectable(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = "eight_diagram",
    })
  end,
  on_use = skel_on_use,
})

skel:addEffect(fk.AskForCardResponse, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and not player:isFakeSkill(self) and
      Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none") and
      not player:prohibitResponse(Fk:cloneCard("jink")) and
      not player:getEquipment(Card.SubtypeArmor)
      and Fk.skills["#eight_diagram_skill"] ~= nil and Fk.skills["#eight_diagram_skill"]:isEffectable(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = "eight_diagram",
    })
  end,
  on_use = skel_on_use,
})

skel:addEffect(fk.FinishJudge, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:isKongcheng() and target == player and player.room:getCardArea(data.card) == Card.Processing
    and data.reason and string.find(data.reason, "eight_diagram")
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askToChoosePlayers(player, {
      targets = player.room.alive_players, min_num = 1, max_num = 1,
      prompt = "#efengqi__kongcheng-give:::"..data.card:toLogString(), skill_name = skel.name
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
  local room = player.room
    room:obtainCard(event:getCostData(self).tos[1], data.card, true, fk.ReasonPrey, player, skel.name)
  end
})

return skel
